﻿package frEngine.shader.filters.vertexFilters
{
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.vertexFilters.def.*;

    public class SwordLightVertexFilter_Normal extends VertexFilter
    {
        public var keyLineNum:int;

        public function SwordLightVertexFilter_Normal(param1:int)
        {
            this.keyLineNum = param1;
            super(FilterType.SwordLightFilter_Normal);
            if (this.keyLineNum <= 0)
            {
                throw new Error("分段数不能小于等于0");
            }
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            return;
        }// end function

        override public function get programeId() : String
        {
            return "SwordLight" + this.keyLineNum;
        }// end function

        public function reInit(param1:int) : Boolean
        {
            if (this.keyLineNum == param1)
            {
                return false;
            }
            this.keyLineNum = param1;
            return true;
        }// end function

        override public function createFragmentUvCoord(param1:Program3dRegisterInstance) : String
        {
            var _loc_2:String = "kil\t{v_kilValue}.x\t\n";
            return _loc_2;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:Array = [];
            _loc_3.push(new ToBuilderInfo("vc1", "{keyLinePos}", false, this.keyLineNum));
            _loc_3.push(new ToBuilderInfo("vc2", "{keyLineRot}", false, this.keyLineNum));
            _loc_3.push(new ToBuilderInfo("vc7", "{const}", false, 1, [2.65, -1, 2, -1]));
            _loc_3.push(new ToBuilderInfo("vf0", "{v_kilValue}", false, 1));
            _loc_3.push(new ToBuilderInfo("va0", FilterName.SKIN_INDICES, false, 4));
            _loc_3.push(new ToBuilderInfo("va2", FilterName.PARAM0, false, 4));
            _loc_3.push(new ToBuilderInfo("va1", FilterName.POSITION, false, 4));
            var _loc_4:String = "";
            _loc_4 = _loc_4 + "mov         \t vt0     \t\t \t vc[va0.x]\t\t\t\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "mov           vt3      \t \t\t vc[va0.z]\t\t\t\t           \t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt4      \t\t \t vt3\t\t\t    vt0       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "dp3         \t vt1.x     \t\t vt4\t\t\t\tvt4\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "sqt           vt5.w      \t\t vt1.x\t\t\t\t\t\t       \t\t\t\t\n";
            _loc_4 = _loc_4 + "div           vt5.w      \t\t vt5.w\t\t\t    vc7.x       \t\t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt5.x      \t\t vt0.w\t\t\t\t{vcConst1}.y\t       \t\t\n";
            _loc_4 = _loc_4 + "sub           vt5.y      \t\t vt3.w\t\t\t\t{vcConst1}.y\t       \t\t\n";
            _loc_4 = _loc_4 + "min           vt5.z      \t\t vt5.x\t\t\t\tvt5.y\t       \t\t\t\t\n";
            _loc_4 = _loc_4 + "nrm           vt4.xyz      \t\t vt4\t\t\t\t\t       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt1      \t\t \t vt0\t\t\t    \tvc[va0.y]       \t\t\n";
            _loc_4 = _loc_4 + "nrm           vt1.xyz      \t\t vt1\t\t\t\t\t       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "add           vt1      \t\t \t vt1\t\t\t    \tvt4       \t\t\t\t\n";
            _loc_4 = _loc_4 + "nrm           vt1.xyz      \t\t vt1\t\t\t\t\t       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt1      \t\t\t vt1\t\t\t\t\tvt5.w       \t\t\t\n";
            _loc_4 = _loc_4 + "add           vt1      \t\t \t vt0\t\t\t    \tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt2      \t\t \t vt3\t\t\t   \t \tvc[va0.w]       \t\t\n";
            _loc_4 = _loc_4 + "nrm           vt2.xyz      \t\t vt2\t\t\t\t\t       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt2      \t\t \t vt2\t\t\t    \tvt4       \t\t\t\t\n";
            _loc_4 = _loc_4 + "nrm           vt2.xyz      \t\t vt2\t\t\t\t\t       \t\t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt2      \t\t\t vt2\t\t\t\t\tvt5.w       \t\t\t\n";
            _loc_4 = _loc_4 + "add           vt2      \t\t \t vt3\t\t\t    \tvt2       \t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt0      \t\t\t vt0\t\t\t\t\tva2.x       \t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt1      \t\t\t vt1\t\t\t\t\tva2.y       \t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt2      \t\t\t vt2\t\t\t\t\tva2.z       \t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt3      \t\t\t vt3\t\t\t\t\tva2.w       \t\t\t\n";
            _loc_4 = _loc_4 + "add           vt0      \t\t\t vt0\t\t\t\t\tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "add           vt0      \t\t\t vt0\t\t\t\t\tvt2       \t\t\t\t\n";
            _loc_4 = _loc_4 + "add           vt0      \t\t\t vt0\t\t\t\t\tvt3       \t\t\t\t\n";
            _loc_4 = _loc_4 + ("mov         \t vt1     \t\t \t vc[va0.x+" + this.keyLineNum + "]\t\t\t\t\t\t\n");
            _loc_4 = _loc_4 + ("mov           vt2      \t \t\t vc[va0.z+" + this.keyLineNum + "]\t\t\t\t       \n");
            _loc_4 = _loc_4 + "dp4 \t\t\t vt3.x \t\t\t\tvt1\t\t\t\t\t\tvt2\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "sge \t\t\t vt3.x \t\t\t\tvt3.x\t\t\t\t\t{vcConst1}.x\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt3.x      \t\tvt3.x\t\t\t\t\tvc7.z       \t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt3.x      \t\tvt3.x\t\t\t\t\t{vcConst1}.z       \t\n";
            _loc_4 = _loc_4 + "mul           vt2      \t\t\t vt2\t\t\t\t\tvt3.x       \t\t\t\n";
            _loc_4 = _loc_4 + "sub           vt3      \t\t \t vt2\t\t\t    \tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt3      \t\t\t vt3\t\t\t\t\tva1.w       \t\t\t\n";
            _loc_4 = _loc_4 + "add           vt3      \t\t\t vt3\t\t\t\t\tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "dp4 \t\t\tvt4.x \t\t\t\tvt3\t\t\t\t\t\tvt3\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "rsq \t\t\tvt4.x \t\t\t\tvt4.x\t\t\t\t\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "mul \t\t\tvt4\t\t\t\t\tvt4.x\t\t\t\t\tvt3\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "crs           vt1.xyz      \t\t vt4\t\t\t\t\tva1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "crs           vt3.xyz      \t\t vt4\t\t\t\t\tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt1      \t\t \t vt1\t\t\t\t\tvc7.z       \t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt1      \t\t \t vt1\t\t\t\t\tvt4.w       \t\t\t\n";
            _loc_4 = _loc_4 + "mul           vt3      \t\t \t vt3\t\t\t\t\tvc7.z       \t\t\t\n";
            _loc_4 = _loc_4 + "add           vt2      \t\t \t va1\t\t\t\t\tvt1       \t\t\t\t\n";
            _loc_4 = _loc_4 + "add           vt2      \t\t \t vt2\t\t\t\t\tvt3       \t\t\t\t\n";
            _loc_4 = _loc_4 + "add           vt0      \t\t\t vt0\t\t\t\t\tvt2       \t\t\t\t\n";
            _loc_4 = _loc_4 + "mov           vt0.w      \t \t {vcConst1}.z\t\t\t\t           \t\t\n";
            _loc_4 = _loc_4 + "mov           {output}      \t vt0\t\t\t\t           \t\t\t\t\n";
            _loc_4 = _loc_4 + "mov           vf0      \t \t\t vt5.z\t\t\t\t           \t\t\t\t\n";
            _loc_4 = param1.toBuild(_loc_4, _loc_3);
            param1.OpType = ECalculateOpType.ViewProj;
            return _loc_4;
        }// end function

    }
}
